﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Transactions {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.utils.*;
    import Engine.*;

    public class Transaction extends EventDispatcher {

        public static const NO_ERROR:int = 0;
        public static const ERROR_AUTH:int = 1;
        public static const OUTDATED_GAME_VERSION:int = 10;
        public static const AUTH_NO_USER_ID:int = 26;
        public static const AUTH_NO_SESSION:int = 27;
        public static const RETRY_TRANSACTION:int = 28;
        public static const FORCE_RELOAD:int = 29;

        protected static var m_transactionId:uint = 1;

        protected const ERROR_USER_DATA_MISSING:int = 2;
        protected const ERROR_INVALID_STATE:int = 3;
        protected const INVALID_DATA:int = 4;
        protected const MISSING_DATA:int = 5;
        protected const ACTION_CLASS_ERROR:int = 6;
        protected const ACTION_METHOD_ERROR:int = 7;
        protected const ERROR_RESOURCE_DATA_MISSING:int = 8;
        protected const NOT_ENOUGH_MONEY:int = 9;
        protected const TRANSPORT_FAILURE_GENERAL:int = 25;

        protected var m_id:int;
        private var m_canPerform:Boolean = true;
        protected var m_functionName:String;
        protected var m_amfWaitHandle:int = 0;
        protected var m_rawResult:Object = null;

        public function Transaction(){
            super(this);
            this.m_id = Utilities.generateUniqueId();
        }
        public function getId():Number{
            return (this.m_id);
        }
        protected function signedCall(_arg1:String, ... _args):void{
            this.m_functionName = _arg1;
            this.logEvent("Batching AMF call");
            TransactionManager.batchCall(this, _arg1, _args, this.onAmfComplete, this.onAmfFault);
        }
        public function startZaspLogging(_arg1:Boolean, _arg2:Boolean):void{
            if (_arg1){
                if (_arg2){
                    this.m_amfWaitHandle = GlobalEngine.zaspManager.zaspWaitStart("AMF-STP", getQualifiedClassName(this));
                } else {
                    this.m_amfWaitHandle = GlobalEngine.zaspManager.zaspWaitStart("AMF", getQualifiedClassName(this));
                };
            };
        }
        public function endZaspLogging():void{
            if (this.m_amfWaitHandle != 0){
                GlobalEngine.zaspManager.zaspWaitEnd(this.m_amfWaitHandle);
                this.m_amfWaitHandle = 0;
            };
        }
        public function perform():void{
        }
        public function set canPerform(_arg1:Boolean):void{
            this.m_canPerform = _arg1;
        }
        public function get canPerform():Boolean{
            return (this.m_canPerform);
        }
        public function get rawResult():Object{
            return (this.m_rawResult);
        }
        protected function onAmfComplete(_arg1:Object):void{
            this.m_rawResult = _arg1;
            this.endZaspLogging();
            if (_arg1){
                if (_arg1.serverTime != null){
                    GlobalEngine.setInternalServerTime(_arg1.serverTime);
                };
                if (_arg1.errorType == NO_ERROR){
                    this.logEvent("Complete");
                    if (_arg1.data != null){
                        this.onComplete(_arg1.data);
                    };
                } else {
                    if (_arg1.errorData){
                        this.logEvent(((("Error " + _arg1.errorType) + " ") + _arg1.errorData));
                    } else {
                        this.logEvent(("Error " + _arg1.errorType));
                    };
                    this.onFault(_arg1.errorType, _arg1.errorData);
                };
            };
        }
        protected function logEvent(_arg1:String):void{
            GlobalEngine.log("Transaction", ((((this.getId() + " (") + this.m_functionName) + "): ") + _arg1));
        }
        final protected function onAmfFault(_arg1:Object, _arg2:int=25, _arg3:String="onAmfFault was called"):void{
            var _local4:String;
            this.logEvent(("Fault " + _arg1));
            for (_local4 in _arg1) {
                GlobalEngine.log("Transaction", ((_local4 + " : ") + _arg1[_local4]));
            };
            this.endZaspLogging();
            this.onFault(_arg2, _arg3);
        }
        protected function onComplete(_arg1:Object):void{
        }
        public function isFaultable():Boolean{
            return (true);
        }
        protected function onFault(_arg1:int, _arg2:String):void{
        }
        public function isInitTransaction():Boolean{
            return (false);
        }
        public function getBatchCallParams():Object{
            return ({});
        }
        public function preAddTransaction():void{
        }
        public function postAddTransaction():void{
        }

    }
}//package Engine.Transactions 
